package com.fhj.movie.adapter;

import java.util.LinkedList;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fhj.movie.activity.HyyLoginActivity;
import com.fhj.movie.entity.FilmEntity;
import com.fhj.movie_fhj_01.R;
import com.fhj.utils.ImageDownload;

public class FilmCurListAdapter extends BaseAdapter {

	private LinkedList<FilmEntity> lists;
	private Context context;
	// private ImageLoader mImageLoader;
	private ImageDownload mImageDownload;

	public FilmCurListAdapter(Context context, LinkedList<FilmEntity> lists) {
		// TODO Auto-generated constructor stub
		this.lists = lists;
		this.context = context;
		// RequestQueue mQueue = Volley.newRequestQueue(context);
		// mImageLoader = new ImageLoader(mQueue, new BitmapCache());

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lists.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if (arg1 == null) {
			
			holder = new ViewHolder();
			arg1 = LayoutInflater.from(context).inflate(
					R.layout.film_cur_lv_item, arg2, false);
			holder.filmImg = (ImageView) arg1
					.findViewById(R.id.film_lv_item_image);
			holder.filmIs3d = (ImageView) arg1
					.findViewById(R.id.film_is_3dimax);
			holder.filmXinpianImg = (ImageView) arg1
					.findViewById(R.id.film_lv_item_xinpian);
			holder.filmTitle = (TextView) arg1
					.findViewById(R.id.film_lv_item_title);
			holder.filmIntro = (TextView) arg1
					.findViewById(R.id.film_lv_item_intro);
			holder.filmToday = (TextView) arg1
					.findViewById(R.id.film_lv_item_today);
			holder.filmSorce = (TextView) arg1
					.findViewById(R.id.film_lv_item_score);
			holder.filmPrePlay = (ImageView)arg1.findViewById(R.id.film_is_preplay);
			holder.filmBuyTicket = (TextView)arg1.findViewById(R.id.film_lv_item_buyticket);
			arg1.setTag(holder);

		} else {

			holder = (ViewHolder) arg1.getTag();

		}
		mImageDownload = ImageDownload.getInstance(context);
		
		FilmEntity film = lists.get(arg0);
		// ImageListener listener = ImageLoader.getImageListener(holder.filmImg,
		// R.drawable.place_holder, R.drawable.place_holder);
		// mImageLoader.get(film.getLogo(), listener);
		mImageDownload.downLoadImage(holder.filmImg, film.getLogo());
		String dimensional = film.getDimensional();

		if ("3D,IMAX".equals(dimensional)) {
			holder.filmIs3d.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.icon_type_3dimax));

		} else if ("3D".equals(dimensional)) {

			holder.filmIs3d.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.icon_type_3d));

		} else if ("2D,IMAX".equals(dimensional)) {
			holder.filmIs3d.setImageDrawable(context.getResources()
					.getDrawable(R.drawable.icon_type_2dimax));
		} else {
			holder.filmIs3d.setVisibility(View.GONE);
		}
		

		
		mImageDownload = ImageDownload.getInstance(context);
		if (film.getIsNew() == 0)
			holder.filmXinpianImg.setVisibility(View.GONE);
		if(film.getMobilePreview()==null)
		   holder.filmPrePlay.setVisibility(View.GONE);
		holder.filmTitle.setText(film.getName());
		holder.filmIntro.setText(film.getHighLight());
		holder.filmToday.setText(film.getScreenings());
		holder.filmSorce.setText(film.getGrade() + "分");
		holder.filmBuyTicket.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Intent intent=new Intent(context,HyyLoginActivity.class);
				context.startActivity(intent);
			}
		});
		Log.i("------","---------->"+film.getId());

		return arg1;
	}

}

class ViewHolder {
	ImageView filmImg;
	ImageView filmIs3d;
	ImageView filmPrePlay;
	ImageView filmXinpianImg;
	TextView filmTitle;
	TextView filmIntro;
	TextView filmToday;
	TextView filmSorce;
	TextView filmBuyTicket ;

}